#coding=utf-8
#对外接口speak
from . import ttb
import pyaudio
import time

class Speaker():
    def __init__(self):
        pass
    
    def __playData(self,data):
        audio = pyaudio.PyAudio()
        stream_out = audio.open(
            format=8,
            channels=1,
            rate=16000, input=False, output=True)
        stream_out.start_stream()
        stream_out.write(data)
        time.sleep(0.2)
        stream_out.stop_stream()
        stream_out.close()
        audio.terminate()

    def speak(self,text):
        data=ttb.ttbObj.my_tts(text)
        self.__playData(data)

speaker=Speaker()
        

    